﻿using EM.OA.DataModel.DBModel;
using EM.OA.DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EM.OA.BLL
{
    public class UserBLL : BLLBase<EMOA_User>
    {
        /// <summary>
        /// 检查用户登录信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns></returns>
        public EMOA_User CheckUserLogin(string userName, string pwd)
        {
            //todo:测试用户
            if (userName.ToLower() == "admin")
            {
                return new EMOA_User();
            }
            using (var db = new EMOAContext())
            {
                return db.EMOA_User.Where(p => p.UserName == userName && p.Password == pwd).FirstOrDefault();
            }
        }

        /// <summary>
        /// 获取用户名称
        /// </summary>
        /// <param name="userID">用户ID，多个以；号间隔</param>
        /// <returns></returns>
        public string GetUserName(string userID)
        {
            using (var db = new EMOAContext())
            {
                string result = "";
                if (userID.IsNotEmpty())
                {
                    List<Guid> idList = new List<Guid>();
                    userID.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ForEach(p =>
                    {
                        idList.Add(Guid.Parse(p));
                    });
                    db.EMOA_User.Where(p => idList.Contains(p.UserID)).Select(p => p.EmployeeName).ForEach(p =>
                    {
                        if (result.IsNullOrEmpty())
                            result = p;
                        else
                            result += ";" + p;
                    });
                }
                return result;
            }
        }
    }
}
